package com.example.com.skills_utf8;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;

import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;

import view.Arcs;

import com.secret.aes;
import com.utils.NetHelper;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class _44Activity extends Activity{

	_44Activity activity = this;
	
	Timer timer = new Timer();
	
	int progress = 0;
	
	
	
	WebView  mWebView ;
	Handler mHandler = new Handler();

	String url = "http://211.152.50.76/sinawear/java_invoke_js.html";
	
	
	@SuppressLint("JavascriptInterface")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_44);
		
		mWebView = (WebView)findViewById(R.id.wv);
		mWebView.getSettings().setJavaScriptEnabled(true);
		
		
		

		mWebView.addJavascriptInterface(new Object() { 

            public void clickOnAndroid() { 

            	
            	// 是不是因为本地网页的原因
            	
            	activity.runOnUiThread( new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						System.out.println("js调用java。");
                    	
                        Toast.makeText(activity, "测试调用java", Toast.LENGTH_LONG).show();

					}
				});
            	
            	/*
                mHandler.post(new Runnable() { 

                    public void run() { 

                    	System.out.println("js调用java。");
                    	
                        Toast.makeText(activity, "测试调用java", Toast.LENGTH_LONG).show();

                    } 

                });
                */ 

            } 

        }, "Android");
		
		
		
		mWebView.loadUrl( url );
		
		
		// 调用网页中js代码
		Button btn_invoke_web_script = (Button)findViewById(R.id.btn_invoke_web_script);
		btn_invoke_web_script.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				mWebView.loadUrl("javascript:test()");
			}
		});
		
		
		
		
		
		
		
		
		
	
		
	}
	
	
	
	
	
}
